package com.myk.game.gobangchess.rooms.oldrooms;

import com.myk.game.gobangchess.DataManager;
import com.myk.game.gobangchess.Room;
import com.myk.game.gobangchess.utils.GridsUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 生存类棋验证
 */
public class SurvivalRoom extends Room {


    private static final int MAX_ROWS = 16;
    private static final int MAX_COLS = 16;

    public SurvivalRoom(String roomName) {
        super(roomName, "不断随机生成怪物，双人合作生存类棋的验证房间", "逆界危机", GridsUtils.createEmptyGrids(MAX_ROWS,MAX_COLS), true, false);
    }

    @Override
    public String getRuleText() {
        //++这里记录构思
        return "每回合随机生成1-3只怪物，怪物暂时只会随机游走，怪物移动和攻击只能2选1，";
    }

    @Override
    public void resetGrids() {
        super.resetGrids();
        //++清空全局变量
    }

    @Override
    protected void doStart() {
        DataManager.noticeAllGameStart(player_black, player_white, roomName);
        overFlag = 1;//重置结束状态：对弈进行中未结束
        playingStartTime = System.currentTimeMillis(); //重置对弈开始时间
        resetGrids();
        initMap();//初始地图
        noticeBlackMove();
        preHistory();
    }

    @Override
    public String getGameInfo() {
        //++写一些自定义绘制
        //++角色用方形棋子来绘制，怪物用圆形棋子来绘制
        return super.getGameInfo();
    }

    @Override
    public void doRule(int row, int col, int value) {
        //++事件监听，流程驱动
    }

    private List<Wall> walls = null;
    private Human blackHuman = null;
    private Human whiteHuman = null;

    private void initMap(){
        //++随机生成两个空降包裹的位置（以后再实现）
        //++随机两个角色位置 （只能生成在空地）
        //++随机生成怪物，从地图边缘生成

        randomMakeWalls();
        randomMakeHumans();
        randomMakeMonsters();
    }

    private void randomMakeMonsters() {

    }

    private void randomMakeHumans() {
        blackHuman = new Human(4,5);
        whiteHuman = new Human(0,15);
    }

    private void randomMakeWalls() {
        //++随机阻拦墙块
        //  （第一步随机决定生成3-6块连续的墙体）
        //  （第二步遍历，并随机决定每块墙体的棋子数量1-6和类型直线or曲折）
        //  （第三步遍历墙体数量，随机决定每个棋子的位置）
        //   墙块生成的规律，该位置为空，该位置和自身墙体相邻，该位置和其它墙体不相邻
        //++暂时左上角放一个墙意思意思
        walls = new ArrayList<>();
        walls.add(new Wall(1,1));
        walls.add(new Wall(1,2));
        walls.add(new Wall(2,1));
    }


    private static class Wall {
        public int id; //用于在初始化时，记录当前墙体的id
        public int row;
        public int col;
        public Wall(int row, int col) {
            this.row = row;
            this.col = col;
        }
    }

    private static class Human {
        public int row;
        public int col;
        public Human(int row, int col) {
            this.row = row;
            this.col = col;
        }
    }

    private static class Monster {
        public int row;
        public int col;
        public int value;
        public Monster(int side, int row, int col) {
            this.row = row;
            this.col = col;
            this.value = side;
        }
    }
}
